package com.shilox.android.app.logitnow;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.shilox.android.app.logitnow.fragment.AddFeelingFragment;
import com.shilox.android.app.logitnow.fragment.ListFeelingsFragment;
import com.shilox.android.app.logitnow.fragment.WelcomeFragment;

public class WelcomeActivity extends FragmentActivity {
	MyPageAdapter pageAdapter;
	ViewPager pager;
	
	ListFeelingsFragment f;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_new);
		List<Fragment> fragments = getFragments();
		pageAdapter = new MyPageAdapter(getSupportFragmentManager(), fragments);
		pager = (ViewPager) findViewById(R.id.viewpager);
		pager.setAdapter(pageAdapter);
		
		pager.setCurrentItem(1);
	}
	
	private List<Fragment> getFragments() {
		List<Fragment> fList = new ArrayList<Fragment>();

		//add AddFeelingFragment
		fList.add(new AddFeelingFragment());
		//add WelcomeFragment
		fList.add(new WelcomeFragment());
		//add Fragment
		f = ListFeelingsFragment.newInstance(1);
		fList.add(f);

		return fList;

	}
	
	@Override
	public void onBackPressed() {
		switch (pager.getCurrentItem()) {
			case 0:
				pager.setCurrentItem(1);
				break;
			case 1:break;
			case 2:
				if(f.getBotonera().getVisibility()!=View.GONE) {
					pager.setCurrentItem(1);
				} else {
					f.showBotonera();
				}
				break;
			default: break;
		}
	}
}

class MyPageAdapter extends FragmentPagerAdapter {
	private List<Fragment> fragments;

	public MyPageAdapter(FragmentManager fm, List<Fragment> fragments) {
		super(fm);
		this.fragments = fragments;
	}

	@Override
	public Fragment getItem(int position) {
		return this.fragments.get(position);
	}

	@Override
	public int getCount() {
		return this.fragments.size();
	}
	
}
